package org.easy.eao;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Map;

import org.easy.eao.executer.Executer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * EAO 接口 动态代理的调用处理类
 * @author Frank
 */
public class EaoHandler implements InvocationHandler {
	
	static final Logger logger = LoggerFactory.getLogger(EaoHandler.class);
	
	private Map<Method, Executer> executers;

	@Override
	public Object invoke(Object proxy, Method method, Object[] parameters)
			throws Throwable {
		if (!executers.containsKey(method))
			return method.invoke(this, parameters);
		
		Executer executer = executers.get(method);
		return executer.execute(method, parameters);
	}

	/**
	 * 设置当前代理的方法执行者映射
	 * @param executers
	 */
	public void setExecuters(Map<Method, Executer> executers) {
		this.executers = executers;
	}

}
